﻿using System;
using System.Collections.Generic;
using System.Text;
using PBO.Data.Util;

namespace PBO.Data.SQLite.DAL
{
    public static class DALHiddenPower
    {
        /// <summary>
        /// 根据属性名称返回觉醒力量IV
        /// </summary>
        public static BaseStats GetHiddenIv(string name)
        {
            const string sql = "select v.[Hp],v.[Atk],v.[Def],v.[Spe],v.[SpA],v.[SpD] from v_hiddentype v where v.[Name] like '%{0}%' limit 1";
            var dt = SQLiteHelper.DbHelperSQLite.ExecuteDataTable(string.Format(sql, name.Trim().ToLower()));
            if (dt != null && dt.Rows.Count > 0)
            {
                var b = new BaseStats(0);
                var dr = dt.Rows[0];
                for (int i = 0; i < 6; i++)
                {
                    b[(StatType)i] = dr[i].ToString().ToInt();
                }
                return b;
            }
            return null;
        }

        public static BaseStats GetHiddenIv(BattleType type)
        {
            if (type == BattleType.None || type == BattleType.Normal) return null;
            return GetHiddenIv((int)type);
        }

        /// <summary>
        /// 根据TypeId返回觉醒力量IV
        /// </summary>
        public static BaseStats GetHiddenIv(int id)
        {
            const string sql = "select v.[Hp],v.[Atk],v.[Def],v.[Spe],v.[SpA],v.[SpD] from v_hiddentype v where v.typeid ={0} limit 1";
            var dt = SQLiteHelper.DbHelperSQLite.ExecuteDataTable(string.Format(sql, id));
            if (dt != null && dt.Rows.Count > 0)
            {
                var b = new BaseStats(0);
                var dr = dt.Rows[0];
                for (int i = 0; i < BaseStats.Types.Length; i++)
                {
                    b[BaseStats.Types[i]] = dr[i].ToString().ToInt();
                }
                return b;
            }
            return null;
        }
    }
}
